// subHoliday/IdentityApproval/identityApproval.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    result: [],
    uid: getApp().globalData.userInfo.id,
    sid: getApp().globalData.userInfo.school_ID,
    ApproveTeacherList: null,
    alreadyApprove: null,
    loading: false,
  },
  // 获取审批列表
  async getApproveTeacherList() {
    this.setData({
      loading: true
    })
    try {
      const json = await getApp().$axios("/getDoubleApproveList?id=" + this.data.uid, "GET")
      if (json.status !== 200) {
        wx.showToast({
          title: '获取列表出错',
          icon: 'none'
        })
        return
      }
      this.setData({
        ApproveTeacherList: json.data,
        alreadyApprove: json.alreadyApprove,
        loading: false
      })
    } catch (error) {
      wx.showToast({
        title: error.msg,
        icon: 'error'
      })
    }
  },
  onChange(e) {
    this.setData({
      result: e.detail,
    });
  },
  // 批量同意
  async agree() {
    wx.showLoading({
      title: '加载中',
    })
    if (this.data.result.length == 0) {
      wx.showToast({
        title: '请选择审批的对象！',
        icon: 'none'
      })
      return
    }
    try {
      const json = await getApp().$axios("/batchApproveDouble", "POST", {
        ids: this.data.result
      })
      wx.hideLoading()
      if (json.status !== 200) {
        wx.showToast({
          title: '审批异常，请重试',
          icon: 'none'
        })
        return
      }
      wx.showModal({
        title: '提示',
        content: json.data,
        showCancel: false,
        complete: (res) => {
          this.getApproveTeacherList()
        }
      })
    } catch (error) {
      wx.showToast({
        title: error.msg,
        icon: 'error'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getApproveTeacherList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})